package com.itheima.socket.tcp.demo13;

import java.io.*;
import java.net.Socket;

public class ClientHandler implements Runnable {

    private Socket socket;
    public ClientHandler(Socket socket){
        this.socket = socket;
    }
    @Override
    public void run() {
        try {
            InputStream inputStream = socket.getInputStream();
            BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream("D:\\2019.7.30heima\\4.wmv"));
            byte[] bytes = new byte[1024];
            int length = -1;
            while ((length = inputStream.read(bytes)) != -1){
                bufferedOutputStream.write(bytes, 0, length);
            }
            OutputStream outputStream = socket.getOutputStream();
            outputStream.write("上传成功".getBytes("UTF-8"));
            bufferedOutputStream.close();
            socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
